package main

import (
	"fmt"
	"net"
	"os"
	"src/lib"
	"time"
)

func main() {
	var buf [512]byte
	// 绑定
	tcpAddr, err := net.ResolveTCPAddr("tcp", "127.0.0.1" + lib.Port)
	lib.CheckError(err)
	// 连接
	conn, err := net.DialTCP("tcp", nil, tcpAddr)
	lib.CheckError(err)
	rAddr := conn.RemoteAddr()
	// 发送
	msg := "{\"key\":\"mq_test1\",\"value\":\"hi server\"}"
	n, err := conn.Write([]byte(msg))
	lib.CheckError(err)
	// 接收
	n, err = conn.Read(buf[0:])
	lib.CheckError(err)
	fmt.Println("Reply form server", rAddr.String(), string(buf[0:n]))
	time.Sleep(time.Second * 2)

	conn.Close()
	os.Exit(0)
}
